﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo002
{
    class Program
    {
            static void Main(string[] args)
            {
                Text10();
            }
            static void Text()
            {
                //输入一行字符串，分别统计出其中英文字母、数字、空格的个数。
                int IsDigit = 0;
                int IsLetter = 0;
                int IsPunctuation = 0;
                int IsWhiteSpace = 0;
                string arr = "abcd e1234 5 . .,./?";
                foreach (char num in arr)
                {
                    if (char.IsDigit(num))
                    {
                        IsDigit++;
                    }
                    else if (char.IsLetter(num))
                    {
                        IsLetter++;
                    }
                    else if (char.IsPunctuation(num))
                    {
                        IsPunctuation++;
                    }
                    else if (char.IsWhiteSpace(num))
                    {
                        IsWhiteSpace++;
                    }
                }
                Console.WriteLine("在arr中数字有{0}个 字母有{1}个  符号有{2}个  空格有{3}个", IsDigit, IsLetter, IsPunctuation, IsWhiteSpace);
            }
            static void Text01()
            {
                //在 Main 方法中创建一个 double 类型的数组，并在该数组中存入 5 名学生的考试成绩(控制台输入)，计算总成绩和平均成绩。
                //要求使用foreach语句实现该功能，
                double[] garden = new double[5];
                double sum = 0.0;
                double avg = 0.0;
                for (int i = 0; i < garden.Length; i++)
                {
                    Console.WriteLine("请输入第" + (i + 1) + "名同学的成绩");
                    garden[i] = double.Parse(Console.ReadLine());
                }
                foreach (double item in garden)
                {
                    sum = sum + item;
                }
                avg = sum / 5;
                Console.WriteLine("总成绩为：{0} 平均成绩为：{1}", sum, avg);
            }
            static void Text02()
            {
                //定义一个方法，实现一维数组的排序功能，从大到小排序。(不要用Array类的方法)
                int num;
                int[] arr = new int[] { 100, 20, 50, 66, 78, 10 };
                Console.WriteLine("排序前：");
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.Write(arr[i] + "  ");
                }
                Console.WriteLine();
                for (int i = 0; i < arr.Length - 1; i++)
                {
                    for (int j = 0; j < arr.Length - i - 1; j++)
                    {
                        if (arr[j] < arr[j + 1])
                        {
                            num = arr[j];
                            arr[j] = arr[j + 1];
                            arr[j + 1] = num;
                        }
                    }
                }
                Console.WriteLine("排序后：");
                for (int i = 0; i < arr.Length; i++)
                {

                    Console.Write(arr[i] + "  ");
                }
            }
            static void Text03()
            {
                //实现查找数组元素索引的功能。
                //定义一个数组，然后控制台输入要查找的元素，返回输入值在数组中最后一次出现的位置。若是找不到，请打印找不到。
                while (true)
                {
                    int index = -1;
                    int[] arr = new int[] { 99, 66, 18, 37, 102, 354, 9999 };
                    Console.WriteLine("一位数组为： ");
                    for (int i = 0; i < arr.Length; i++)
                    {
                        Console.Write(arr[i] + "  ");
                    }
                    Console.WriteLine();
                    Console.WriteLine("请输入要查找的数字");
                    int num = int.Parse(Console.ReadLine());
                    for (int i = arr.Length - 1; i >= 0; i--)
                    {
                        if (arr[i] == num)
                        {
                            index = i;
                        }
                    }
                    if (index == -1)
                    {
                        Console.WriteLine("找不到该数");
                    }
                    else
                    {
                        Console.WriteLine("最后一次出现位置在  arr[" + index + "]");
                    }

                }

            }
            static void Text04()
            {
                //在 Main 方法中创建一个字符串类型的数组，并存入 5 个值，然后将数组中下标是偶数的元素输出。
                string[] arr = new string[5] { "1", "2", "3", "4", "5" };
                for (int i = 0; i < arr.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        Console.WriteLine("a[" + i + "]" + "=" + arr[i]);
                    }

                }
            }
            static void Text05()
            {
                //乘法表
                for (int i = 1; i < 10; i++)
                {
                    for (int j = 1; j <= i; j++)
                    {
                        Console.Write(j + "*" + i + "=" + (j * i) + "\t");
                    }
                    Console.WriteLine();
                }
            }
            static void Text06()
            {
                //空心正方形
                Console.WriteLine("请输入正方形的边长");
                int d = int.Parse(Console.ReadLine());
                for (int i = 1; i <= d; i++)
                {
                    for (int j = 1; j <= d; j++)
                    {
                        if (i == 1 || i == d || j == 1 || j == d)
                        {
                            Console.Write("* ");
                        }
                        else
                        {
                            Console.Write("  ");
                        }
                    }
                    Console.WriteLine();
                }
            }
            static void Text07()
            {
                //菱形
                Console.WriteLine("请输入菱形的边长");
                int num = int.Parse(Console.ReadLine());
                for (int i = 1; i <= num; i++)
                {
                    for (int j = i; j <= num; j++)
                    {
                        Console.Write(" ");
                    }
                    for (int f = 1; f <= (2 * i) - 1; f++)
                    {
                        Console.Write("*");
                    }
                    Console.WriteLine();
                }
                for (int i = num - 1; i >= 1; i--)
                {
                    for (int j = i; j <= num; j++)
                    {


                        Console.Write(" ");



                    }
                    for (int f = 1; f <= (2 * i) - 1; f++)
                    {
                        Console.Write("*");
                    }
                    Console.WriteLine();
                }
            }
            static void Text08()
            {
                //用户输入正方形边长，用* 打印出实心正方形。
                Console.WriteLine("请输入正方形的边长");
                int d = int.Parse(Console.ReadLine());
                for (int i = 0; i < d; i++)
                {
                    for (int j = 0; j < d; j++)
                    {
                        Console.Write(" *");
                    }
                    Console.WriteLine();
                }
            }
            static void Text09()
            {
                int index = -1;
                int[] arr = new int[] { 100, 80, 70, 50, 40, 30, 20, 10 };
                Console.WriteLine("请输入一个整数");
                int num = int.Parse(Console.ReadLine());
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] <= num)
                    {
                        index = i;
                        break;
                    }
                    else
                    {
                        index = arr.Length + 1;
                    }
                }
            }
            static void Text10()
            {
                Console.WriteLine("请输入杨辉三角的行数");
                int num = Convert.ToInt32(Console.ReadLine());
                int[][] arr = new int[num][];
                for (int i = 0; i < num; i++)
                {
                arr[i] = new int[i + 1];
                }
                for (int i = 0; i < num; i++)
                {
                    arr[i][0] = 1;
                    arr[i][i] = 1;
                }
                for (int i = 2; i < num; i++)
                {
                    for (int j = 1; j < i ; j++)
                    {
                        arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
                    }
                }
                for (int i = 0; i < num; i++)
                {
                    for (int e = 0; e <num-i; e++)
                    {
                        Console.Write(" ");
                    }
                    for (int j = 0; j <= i; j++)
                    {
                        Console.Write(arr[i][j]+" ");
                    }
                    Console.WriteLine();
                }
            }
        }
    }

